﻿using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using Volo.Abp.EntityFrameworkCore.Modeling;

namespace Loong.Admin.Roles
{
    public class RoleConfiguration : IEntityTypeConfiguration<Role>
    {
        public void Configure(EntityTypeBuilder<Role> b)
        {
            b.ToTable("Roles");

            b.ConfigureByConvention();

            b.Property(r => r.Name)
                .IsRequired()
                .HasMaxLength(RoleConsts.MaxNameLength);

            b.Property(r => r.NormalizedName)
                .IsRequired()
                .HasMaxLength(RoleConsts.MaxNormalizedNameLength);

            b.HasMany(r => r.Claims)
                .WithOne()
                .HasForeignKey(rc => rc.RoleId)
                .IsRequired();

            b.HasIndex(r => r.NormalizedName);
        }
    }
}
